package com.lqq.school.controller;



import com.lqq.school.domain.Clazz;
import com.lqq.school.mapper.ClazzMapper;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 班级实体 前端控制器
 * </p>
 *
 * @author lqq
 * @since 2021-06-11
 */
@Controller
public class ClazzController {

    @Resource
    private ClazzMapper clazzMapper;

    @GetMapping("/toClazz")
    public String toClazz(Model model) {
        List<Clazz> clazzes = clazzMapper.selectList(null);
        model.addAttribute("list", clazzes);
        return "/admin/classlist";
    }

    @GetMapping("/toClaUpdate/{clazzId}")
    public String toUpdate(@PathVariable("clazzId") int clazzId, Model model) {
        Clazz clazz = clazzMapper.selectById(clazzId);
        //System.out.println(clazz);
        model.addAttribute("cla", clazz);
        return "/admin/classupdate";
    }

    @PostMapping("/update")
    public String update(Clazz clazz) {
        //System.out.println(clazz);
        int update = clazzMapper.updateById(clazz);
        if (update > 0) {
            System.out.println("更新成功！");
        }
        return "redirect:/toClazz";
    }


}

